package tmt.usercenter.web.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.tmt.annotation.Select2OptionItem;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;

@Getter
@Setter
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
@JsonIdentityInfo(generator = JSOGGenerator.class)
public class TmtRoleAuthority extends BaseDomain implements Serializable {

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name="role_id", nullable = false)
    private TmtRole role;

    @Select2OptionItem
    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name="authority_id", nullable = false)
    private TmtAuthority authority;

    public TmtRoleAuthority(){}

    public TmtRoleAuthority(TmtRole role, TmtAuthority authority){
        this.role = role;
        this.authority = authority;
    }
}
